<template>
	<view class="main animated fadeIn faster">
		<view class="content position-fixed z-index-99" :style="{'paddingTop':$store.state.statusBarHeight+'px','top':'0'}">
			<view class="title">
				<view class="pl-2" @click="goback"><text class="iconfont icon-31fanhui1 font30"></text></view>
				<text>{{title}}</text>
			</view>
		</view>
		<view class="pl-3 list-mt-100">
			<view class="item mb-4 d-flex d-flex-between d-flex-middle">
				<text class="font32" style="color: #231815;">搭子铃状态</text>
				<switch :checked="openFlag"  @change="handleSwitchChange" color="#e8b2dc" style="transform:scale(0.7)"/>
			</view>
			<view class="pb-5">
				<view class="d-flex d-flex-between d-flex-middle">
					<text class="font32">安全距离保护</text>
					<switch :checked="safeDistanceProtectFlag"   @change="handleSafeDistanceChange" color="#e8b2dc" style="transform:scale(0.7)"/>
				</view>
				<view class="font22" style="color: #C7C8C9;">不匹配距我500m以内的Ta</view>
			</view>
		</view>
		<view class="ml-5" style="width: 100%;">
			<view class="d-flex position-relative mb-0">
				<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202048.png" class="position-absolute" style="width: 33rpx; height: 35rpx; top: 15rpx; left: 35rpx;"></image>
				<view class="font34 font-bold pt-1 linerbg-b pb-5" style="border-radius: 50rpx 50rpx 0 0; width: 100%; margin-right: 100rpx; padding-left: 80rpx;">搭子铃筛选</view>
			</view>
			 <view class="d-flex d-flex-between mb-7" @click="openSex">
			      <text class="font32">Ta的性别</text>
			      <view class="d-flex mr-5">
			        <text class="font30 mr-1" style="color: #878787; margin-top: 4rpx;">
			          {{ sex === 0 ? '不限' : (sex === 1 ? '男' : '女') }}
			        </text>
			        <view class="icon mr-5">
			          <image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%201990.png" style="width: 18rpx; height: 26rpx;"></image>
			        </view>
			      </view>
			    </view>
			
			<view class="d-flex-column mb-8" @click="openAge">
				<view class="d-flex d-flex-between">
					<text class="font32">Ta的理想年龄</text>
					<view class="d-flex mr-5">
						<text class="font30 mr-1" style="color: #878787; margin-top: 4rpx;">{{age==0?"不限":age}}</text>
						<view class="icon mr-5">
							<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%201990.png" style="width: 18rpx; height: 26rpx;"></image>
						</view>
					</view>
				</view>
				<view class="font22" style="color: #C7C8C9;">匹配最接近这个年龄的Ta</view>
			</view>
			<!-- <view class="d-flex d-flex-between mb-7" @click="skin">
				<text class="font32">搭子铃音效</text>
				<view class="d-flex mr-5">
					<view class="icon mr-5">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%201990.png" style="width: 18rpx; height: 26rpx;"></image>
					</view>
				</view>
			</view> -->
			<view class="mr-5 mb-7">
				<view class="d-flex d-flex-between d-flex-middle mr-3">
					<text class="font32">搭子铃位置信息</text>
					<switch :checked="locationFlag" @change="handleLocationChange"  color="#e8b2dc" style="transform:scale(0.7)"/>
				</view>
				<view class="font22" style="color: #C7C8C9;">关闭后每日匹配次数受限</view>
			</view>
			<view class="d-flex d-flex-between mb-7" >
				<text class="font32">每日匹配次数</text>
				<view class="d-flex mr-5">
					<text class="font30 mr-2" style="color: #878787; margin-top: 4rpx;">系统默认</text>
					<!-- <view class="icon mr-5">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%201990.png" style="width: 18rpx; height: 26rpx;"></image>
					</view> -->
				</view>
			</view>
			<view class="d-flex position-relative mb-3">
				<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%202024.png" class="position-absolute" style="width: 33rpx; height: 35rpx; top: 15rpx; left: 35rpx;"></image>
				<view class="d-flex d-flex-middle pt-1 linerbg-pink pb-5" style="border-radius: 50rpx 50rpx 0 0; width: 100%; margin-right: 100rpx; padding-left: 80rpx;">
					<view class="font34 font-bold">搭子铃筛选</view>
					<view class="ml-2">超级星人尊享</view>
				</view>
			</view>
			<!-- <view class="d-flex d-flex-between mb-5" @click="skin">
				<text class="font32">搭子铃皮肤</text>
				<view class="d-flex mr-5">
					<view class="icon mr-5">
						<image src="https://yuexiaoda-1314351529.cos.ap-shanghai.myqcloud.com/app/%E7%BB%84%201990.png" style="width: 18rpx; height: 26rpx;"></image>
					</view>
				</view>
			</view> -->
			<view class="d-flex d-flex-between d-flex-middle mr-5 mb-5" @click="ifsvip">
				<text class="font32" style="color: #231815;">优先看瞬间>5的用户</text>
				<switch class="mr-3" :checked="activeCoupleFlag" @change="handleactiveCoupleChange" :disabled="$store.state.user.accountType!= 3" color="#e8b2dc" style="transform:scale(0.7)"/>
			</view>
			<view class="d-flex d-flex-between d-flex-middle mr-5 mb-3" @click="ifsvip">
				<text class="font32" style="color: #231815;">优先看超级星人</text>
				<switch class="mr-3" :checked="svipFlag"  @change="handlesvipFlagChange" :disabled="$store.state.user.accountType!= 3"  color="#e8b2dc" style="transform:scale(0.7)"/>
			</view>
		</view>
		  <uni-popup ref="popup" type="bottom" background-color="#fff" border-radius="16px 16px 0 0" style="z-index: 999;">
		      <view class="d-flex d-flex-between pb-6 mt-6 px-6">
		          <view style="color: #9E9D9D;" @click="closeSex">取消</view>
		          <view style="color: #66CCCC;" @click="confirmSex(sex)">确认</view>
		      </view>
		      <picker-view class="popup-content px-2" @change="sexChange" >
		          <picker-view-column>
		              <view class="option" >不限</view>
		              <view class="option" >男</view>
		              <view class="option" >女</view>
		          </picker-view-column>
		      </picker-view>
		  </uni-popup>
		  <uni-popup ref="Agepopup" type="bottom" background-color="#fff" border-radius="16px 16px 0 0" style="z-index: 999; overflow: hidden;">
		      <view class="d-flex d-flex-between pb-6 mt-6 px-6">
		          <view style="color: #9E9D9D;" @click="closeAge">取消</view>
		          <view style="color: #66CCCC;" @click="confirmAge(age)">确认</view>
		      </view>
		      <picker-view class="popup-content px-2" @change="ageChange">
		          <picker-view-column>
		              <view class="option" v-for="(i,index) in ages" :key="dex">{{i}}</view>
		              
		          </picker-view-column>
		      </picker-view>
		  </uni-popup>
		 <!-- <uni-popup ref="pipeipopup" type="bottom" background-color="#fff" border-radius="16px 16px 0 0" style="z-index: 999;">
		      <view class="d-flex d-flex-between pb-6 mt-6 px-6">
		          <view style="color: #9E9D9D;" @click="closepipei">取消</view>
		          <view style="color: #66CCCC;" @click="confirmpipei(pipei)">确认</view>
		      </view>
		      <picker-view class="popup-content px-2" @change="pipeiChange" >
		          <picker-view-column>
		              <view class="option" >系统默认</view>
		              <view class="option" >男</view>
		              <view class="option" >女</view>
		          </picker-view-column>
		      </picker-view>
		  </uni-popup> -->
	</view>
</template>

<script>
	import TitleBarVue from '../../components/TitleBar.vue';
	import store from '@/store/index.js';
	import { DaziApi } from '../../http/Dazi';
	export default {
		data() {
			return {
				display: "none;",
				bgcolor: "#fff",
				openFlag:true,//是否开启搭子铃配置
				safeDistanceProtectFlag:true,//是否开启安全距离配置
				locationFlag:true,//是否开启搭子铃位置信息
				matchCount:0,//搭子铃匹配次数
				activeCoupleFlag:false,//优先匹配活跃搭子开关
				svipFlag:false,//优先匹配超级会员
				current: 0,
				// pipei:0,
				setParam:{},//设置参数
				 showSexPicker: false, // 控制弹窗显示隐藏
				sex: 0,
				ages:["不限","18-25","25-30","30-35","35-40","40-45","45-50"],
				indicatorStyle: `height: 80px;`,
				age:0,
				title: '搭子铃设置'
			}
		},
		components: {TitleBarVue},
		 onLoad() {
			 console.log("加载数据");
			 uni.getStorage({
			   key: 'set',
			   success: res => {
			     const setParam = JSON.parse(res.data);
			   if(setParam!={}){
			   //	console.log(setParam.openFlagm,setParam.safeDistanceProtectFlag,setParam.requiredGender,setParam.locationFlag,setParam.activeCoupleFlag );
			   
			   			   this.openFlag = setParam.openFlag === 1?true:false;
			   			   this.safeDistanceProtectFlag = setParam.safeDistanceProtectFlag === 1?true:false;
			   			   this.sex = setParam.requiredGender;
			   			  
			   			   this.locationFlag = setParam.locationFlag === 1?true:false;
			   			   this.activeCoupleFlag = setParam.activeCoupleFlag === 1?true:false;
			   			 
			   			   				
			    //  console.log(this.openFlag,this.safeDistanceProtectFlag,this.sex,this.locationFlag,this.activeCoupleFlag);
			   	   }
			  
			   }
			 });
			
			
				   
		    },
		methods: {
			handleSwitchChange(e) {
			    
			         const isChecked = e.detail.value;
			     
			    
			     
			       this.openFlag = isChecked;
			      
			    },
			handleSafeDistanceChange(e){
				
				    const isChecked = e.detail.value;
				
				
				this.safeDistanceProtectFlag=isChecked;
				 
				
				
			},	
			handleLocationChange(e){
				const isChecked = e.detail.value;
				
				
				this.locationFlag=isChecked;
				
			},
			handleactiveCoupleChange(e){
				const isChecked = e.detail.value;
				
				
				this.activeCoupleFlag=isChecked;
				
			},
			handlesvipFlagChange(e){
				const isChecked = e.detail.value;
				
				
				this.svipFlag=isChecked;
				
			},
			// async setAccelerate(param){
			// 	let res=await DaziApi.setAccelerate(param);
			// },
			goback() {
				this.setParam.openFlag=this.openFlag?1:0;
				this.setParam.safeDistanceProtectFlag=this.safeDistanceProtectFlag?1:0;
				this.setParam.requiredGender=this.sex;
				this.setParam.requiredAgeFrom=this.age==0?0:this.age.split('-')[0];
				 this.setParam.requiredAgeTo=this.age==0?0:this.age.split('-')[1];
				 this.setParam.locationFlag=this.locationFlag?1:0;
				 this.setParam.activeCoupleFlag=this.activeCoupleFlag?1:0;
				 this.setParam.svipFlag=this.svipFlag?1:0;
				uni.setStorage({
				  key: 'set',
				  data: JSON.stringify(this.setParam),
				  success: () => console.log('存储成功')
				});
				
				 
				
				        // 将数据存储到本地存储
				        uni.setStorage({
				            key: 'setParam',
				            data: this.setParam,
				            success: () => {
				                console.log('Attempting to store data success:', this.setParam);
				                // 返回上一页
				                uni.navigateBack({
				                    delta: 1
				                });
				            },
				            fail: (err) => {
				                console.error('Failed to store data:', err);
				                // 如果存储失败，可以选择提示用户或重试
				                uni.showToast({
				                    title: '数据存储失败，请稍后再试',
				                    icon: 'none'
				                });
				            }
				        });
			},
			ifsvip(){
				 if(this.$store.state.user.accountType!=3){
					 uni.showModal({
					   
					   content: '您暂时还不是Svip，是否开通Svip？',
					   success: (res) => {
					     if (res.confirm) {
					      
					      uni.navigateTo({
					      	url:'/pagesMain/member/member'
					      })
					     } else if (res.cancel) {
					 							 
					       // console.log('用户点击取消');
					       // 不执行任何操作，用户取消退出
					     }
					   }
					 });
				 }else{
					 
				 }
			},
			// pipei(){
			// 	this.$refs.pipeipopup.open();
			// },
			// closepipei(){
			// 	this.$refs.pipeipopup.close();
			// },
			// confirmpipei(){
			// 	this.$refs.pipeipopup.close();
			// },
			// pipeiChange(){
				
			// },
			skin(){
				uni.showToast({
				    title: '该功能暂未开发',
				    icon: 'none', // 使用'none'图标，只显示文字
				    duration: 1000 // 显示持续时间
				  });	
			},
			openAge(){
				this.$refs.Agepopup.open();
			},
			openSex() {
			        this.$refs.popup.open();
			      },
			closeAge(){
					  this.$refs.Agepopup.close();
				  },
			closeSex() {
			        this.$refs.popup.close();
			      },
			confirmAge(age){
					  this.$refs.Agepopup.close();
				  },
			confirmSex(index) {
			                  this.$refs.popup.close(); // 关闭弹出层
			              },
			sexChange(e) {
			                  const val = e.detail.value[0]; // 获取选中的索引
			                  this.sex = val; // 更新选中的索引
			                  
			              },
			ageChange(e){
					  
					  const val = e.detail.value[0];
					  this.age=this.ages[val];
				  },
			     
		}
	}
</script>

<style scoped lang="scss">
	.uni-popup__wrapper {
		height: 210px;
		border-radius: 50rpx;
	}
	.picker-view .picker-view-column .item {
		height: 70px !important;
		line-height: 70px !important;
	}
	
	.popup-content {
	height: 180rpx !important;
	  color: #1f1f1f;
	  padding: 40rpx 60rpx 0;
	}
	
	.option {
	  box-sizing: border-box;
	  border-radius: 10rpx;
	  color: #333333;
	  font-size: 26rpx;
	  width: 100%;
	  margin-top:0rpx;
	  height: 90rpx;
	  padding-left: 20rpx;
	  display: flex;
	  align-items: center;
	  justify-content: center;
	}
	
	.option:first-child {
	  margin-top: 0;
	}
	
	.separator {
	  height: 1rpx;
	  background-color: #e0e0e0;
	  margin: 20rpx 0;
	}
.main {
	background: #fff;
	overflow: hidden;
	.content {
		width: 100%;
		overflow: hidden;
	}
	.list {
		background-color: #fcfbfc;
		border-radius: 10rpx;
		margin: 20rpx 20rpx 30rpx;
		padding: 0 20rpx 20rpx 40rpx;
		.item {
			display: flex;
			justify-content: space-between;
			padding: 30rpx 0;
			border-bottom: 1px solid #e8e8e8;
			text {
				font-size: 32rpx;
				color: #555;
			}
			.icon {
				image {
					margin: 0 30rpx 8rpx 12rpx;
					width: 12rpx;
					height: 24rpx;
				}
				text {
					font-size: 28rpx;
				}
			}
		}
	}
	.clearCache {
		padding: 0 20rpx 0rpx 40rpx;
		.item {
			border: 0;
		}
	}
	.popup_box {
		width: 100%;
		height: 100vh;
		background-color: rgba(0, 0, 0, .4);
		position: fixed;
		top: 0;
		left: 0;
		.PswPopup {
			width: 450rpx;
			height: 500rpx;
			border-radius: 30rpx;
			background-color: #fff;
			position: absolute;
			top: 50%;
			left: 50%;
			transform: translate(-50% ,-50%);
			padding: 0 50rpx;
			overflow: hidden;
			.title {
				width: 100%;
				font-size: 36rpx;
				display: flex;
				justify-content: center;
				padding: 30rpx 0;
			}
			input {
				height: 80rpx;
				border-bottom: 1px solid #ccc;
				font-size: 24rpx;
				margin-bottom: 10rpx;
				padding-left: 15rpx;
				font-weight: normal;
			}
			.btns {
				height: 60rpx;
				margin-top: 60rpx;
				float: right;
				button {
					padding: 8rpx 40rpx;
					border-radius: 15rpx;
					margin: 0 30rpx;
				}
			}
		}
	}
}
.title {
	display: flex;
	align-items: center;
	font-weight: 700;
	height: 80rpx;
	.goback {
		image {
			margin-left: 50rpx;
			width: 20rpx;
			height: 30rpx;
		}
	}
	text {
		flex: 1;
		margin-right: 50rpx;
		font-size: 34rpx;
		text-align: center;
	}
}
.pt-300 {
	padding-top: 300rpx;
}
.list-mt-100 {
	margin: 200rpx 20rpx 30rpx !important;
}
.linerbg-b {
	background: linear-gradient( 180deg, #61D1E5 0%, rgba(106,211,230,0.94) 10%, rgba(131,219,234,0.78) 29%, rgba(172,230,241,0.52) 54%, rgba(227,247,250,0.17) 86%, rgba(255,255,255,0) 100%);
}
.linerbg-pink {
	background: linear-gradient( 180deg, #E8BAFC 0%, rgba(233,189,252,0.95) 9%, rgba(236,199,252,0.8) 27%, rgba(241,215,253,0.56) 50%, rgba(249,237,254,0.25) 79%, rgba(255,255,255,0) 100%);
}
.content {
	width: 100%;
	background-color: #fff !important;
}
.content .title {
	display: flex;
	align-items: center;
	height: 80rpx;
	padding-right: 47rpx;
	border-bottom: 1px solid rgba(204, 204, 204, .2);
}
.content .title text {
	flex: 1;
	font-size: 32rpx;
	text-align: center;
	font-weight: normal;
}
.z-index-99 {
	z-index: 99;
}
</style>
